package com.onpositive.wiki3.db.impl;

import com.onpositive.wiki3.db.catmodel.Category;
import com.onpositive.wiki3.db.catmodel.ICategoryMatcher;
import com.onpositive.wiki3.db.catmodel.matches.SelfLinksRemover;

public final class BackLinksRemover implements ICategoryMatcher {
	
	int level=0;
	
	public BackLinksRemover(int level){
		this.level=level;
	}
	@Override
	public int accept(Category st) {		
		if (st.distance()<level){
			
			Category[] parents = st.getParentsCategories();
			for (Category categories:parents){
				if (categories.distance()>=st.distance()){
//				
					//if (st.distance()<5|| categories.hasParent(st, 8)){
						SelfLinksRemover.recordRemoval(st);
						//if (st.toString().contains(categories.toString())){
							categories.unregisterChild(st);
						//}
//						else{
//							System.out.println(categories+":"+st);
//						}
					//}					
				}
			}
		}					
		return 0;
	}
}